#ifndef SPYKIT_ORZ
#define SPYKIT_ORZ

#include <Windows.h>

#define SPY_MEMORY_ID	"00484340166978069456"

typedef struct assember_address
{
	DWORD origianl_call_address;
	DWORD original_call_offset;
	DWORD spy_call_offset;
}ASSEMBER_ADDRESS;

#define SPY_MAX		10

class SpyKit
{
public:
	SpyKit();
	~SpyKit();

public:
	void	clean();

public:
	void*	openMap(LPCSTR memory_id = SPY_MEMORY_ID);

public:

	int		initHandleByPID(DWORD processID);
	int		setCall(DWORD ORI_call_address,DWORD SPY_call_address);
	int		beginHook();
	int		stopHook();

public:
	DWORD	getOriginalCallAddress(int index);

	void*	getMapMemory(){return mapMemory;}
	HANDLE	getProcessHandle(){return phandle;}
private:
	HANDLE	phandle;

	HANDLE	mapHandle;
	void*	mapMemory;

	bool	isHook;
	int		SpyCallNumber;
	ASSEMBER_ADDRESS hookCalls[SPY_MAX];

private:
	int		SpyError(char* message);

};

#endif



/**********			How to use			***************
***********			dll file example	***************

typedef struct hellokity
{
	DWORD ProcessID;
	DWORD instructionAddress[LESS_THAN_SPYMAX]; 
	char data[MAX_LEN];
}HELLOKITTY;

SpyKit* kit = NULL;

DWORD ORIGINAL_CALL_ADDRESS;
DWORD HOOK_ADDRESS_RETN;

void __declspec(naked) __stdcall SpyCall0()
{
	_asm
	{
		pop HOOK_ADDRESS_RETN
	}

	ORIGINAL_CALL_ADDRESS = kit->getOriginalCallAddress(0);
	_asm
	{
		call Call_Original_Address;
		
		push HOOK_ADDRESS_RETN
		ret;
	}
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpReserved)
{
	if(kit == NULL){kit = new SpyKit();}
	switch(fdwReason)
	{
	case DLL_PROCESS_ATTACH:
		{
			kity  =	(HELLOKITTY*)kit->openMap();
			if(kity == NULL){return TRUE;} 
			kit->initHandleByPID(kity->ProcessID);
			kit->setCall(kity->instructionAddress[0],(DWORD)SpyCall0);
			kit->beginHook();
		}
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		{
			delete kit;
			kit = NULL;
		}
		break;
	}

	return TRUE;
}
******************************/